package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import Entity.OrderReport;
import java.awt.Font;
import java.util.Date;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * this is the GUI for view orders report.
 * @author Shahar Shelly
 */
public class ViewOrdersReport extends JFrame {

	private JPanel contentPane;
	private JTextField startDate;
	private JTextField endDate;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_3;
	private JTextField textField_4;
	JFrame frame;
	JPanel lastPanel;
	public void setLastPanel (JPanel panel)
	{
		this.lastPanel=panel;
	}
	public void setFrame (JFrame frame)
	{
		this.frame=frame;
	}

	/**
	 *  is the constructor. it has a table to chose from and save after validate.
	 */
	public ViewOrdersReport(OrderReport o) 
	{
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 760, 326);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.setLayout(null);
		
		final JLabel lblOrderReport = new JLabel("Order Report");
		lblOrderReport.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblOrderReport.setBounds(82, 11, 93, 14);
		contentPane.add(lblOrderReport);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Start Date", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 33, 98, 43);
		contentPane.add(panel);
		panel.setLayout(null);
		
		startDate = new JTextField();
		startDate.setBounds(6, 16, 86, 20);
		panel.add(startDate);
		startDate.setColumns(10); 
		startDate.setText(o.getStart().getDate()+"/"+(o.getStart().getMonth()+1)+"/"+(o.getStart().getYear()+1900));
		this.startDate.setEditable(false);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "End Date", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setBounds(10, 77, 98, 43);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		endDate = new JTextField();
		endDate.setBounds(6, 16, 86, 20);
		panel_1.add(endDate);
		endDate.setColumns(10);
		endDate.setText(o.getEndDate().getDate()+"/"+(o.getEndDate().getMonth()+1)+"/"+(o.getEndDate().getYear()+1900));
		endDate.setEditable(false);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(null, "Description", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(118, 36, 221, 84);
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		final JTextPane textPane = new JTextPane();
		textPane.setBounds(6, 16, 205, 57);
		panel_2.add(textPane);
		
		JButton btnCancel = new JButton("Return");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				frame.setContentPane(lastPanel);
				frame.setVisible(true);
			}
		});
		btnCancel.setBounds(203, 251, 89, 23);
		contentPane.add(btnCancel);
		
		JLabel lblNumberOfOrders = new JLabel("Number of Orders:");
		lblNumberOfOrders.setBounds(10, 134, 152, 14);
		contentPane.add(lblNumberOfOrders);
		
		textField = new JTextField();
		textField.setBounds(209, 131, 48, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		this.textField.setText(String.valueOf(o.getNumOfOrders()));
		this.textField.setEditable(false);
		
		JLabel lblNumberOfSubscriptions = new JLabel("Number of Subscriptions:");
		lblNumberOfSubscriptions.setBounds(10, 159, 165, 14);
		contentPane.add(lblNumberOfSubscriptions);
		
		JLabel lblNumberOfInadvance = new JLabel("Number of In-Advance orders:");
		lblNumberOfInadvance.setBounds(10, 184, 174, 14);
		contentPane.add(lblNumberOfInadvance);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(209, 156, 48, 20);
		contentPane.add(textField_1);
		this.textField_1.setText(String.valueOf(o.getNumOfSubs()));
		this.textField_1.setEditable(false);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(209, 181, 48, 20);
		contentPane.add(textField_3);
		this.textField_3.setText(String.valueOf(o.getNumOfInAdvance()));
		this.textField_3.setEditable(false);
		
		JLabel lblParkingLotNumber = new JLabel("Parking Lot Number:");
		lblParkingLotNumber.setBounds(185, 12, 129, 14);
		contentPane.add(lblParkingLotNumber);
		
		textField_4 = new JTextField();
		textField_4.setBounds(313, 9, 26, 20);
		contentPane.add(textField_4);
		textField_4.setColumns(10);
		this.textField_4.setText(String.valueOf(o.getParkingLot()));
		this.textField_4.setEditable(false);
	}
	public void close()
	{
		WindowEvent windowclose=new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
		Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(windowclose);
	}
}
